﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ArrowButton : MonoBehaviour
{
    public int ptr { get; set; }
    [NonSerialized]
    public int maxPtr;
    public Button arrowLeft;
    public Button arrowRight;
    public TMP_Text number;
    public event Action<int> Left;
    public event Action<int> Right;

    public void Init(Action<int> left,Action<int> right,int maxPtr)
    {
        arrowLeft.onClick.AddListener(LeftEvent);
        arrowRight.onClick.AddListener(rightEvent);
        left.Invoke(ptr);
        right.Invoke(ptr);
        Left = left;
        Right = right;
        number.text = $"{ptr}/{maxPtr}";
        this.maxPtr = maxPtr;
    }
    private void LeftEvent()
    {
        if (ptr > 0)
        {
            ptr--;
            number.text = $"{ptr}/{maxPtr}";
            Left.Invoke(ptr);
        }
    }
    private void rightEvent()
    {
        if (ptr < maxPtr)
        {
            ptr++;
            number.text = $"{ptr}/{maxPtr}";
            Right.Invoke(ptr);
        }
    }


}

